<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script type="text/javascript" src="../js/vue.min.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>
    <link type="text/css" rel="stylesheet" href="../css/bootstrap.min.css">
    <title>Document</title>
    <style>
        .inner {
            background-color: blue;
            height: 200px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="inner container" @click="divHandler1">
            <!-- 使用.stop阻止时间的冒泡行为 -->
            <button class="btn btn-default" @click.stop="btnHandler1">点击我</button>
        </div>

        <!-- 使用.prevent阻止默认行为，使用.once只触发事件处理函数一次 -->
        <a href="http://www.baidu.com" @click.prevent.once="toBaidu">点击跳转百度</a>

        <!-- 使用.capture实现捕获触发事件的机制 -->
        <div class="inner container" @click.capture="divHandler2">
            <button class="btn btn-default" @click="btnHandler2">点击我</button>
        </div>

        <!-- 使用.self实现只有点击当前元素时才触发事件处理函数 -->
        <div class="inner container" @click.self="divHandler3">
            <button class="btn btn-default" @click="btnHandler3">点击我</button>
        </div>
    </div>

    <script>
        var vm = new Vue({
            el: "#app",
            data: {

            },
            methods: {
                divHandler1() {
                    alert("触发了inner div 的点击事件");
                },
                btnHandler1() {
                    alert("触发了btn 的点击事件");
                },
                toBaidu() {
                    alert("正在跳转至百度");
                },
                divHandler2() {
                    alert("触发了inner div 的点击事件");
                },
                btnHandler2() {
                    alert("触发了btn 的点击事件");
                },
                divHandler3() {
                    alert("触发了inner div 的点击事件");
                },
                btnHandler3() {
                    alert("触发了btn 的点击事件");
                }
            }
        });
    </script>
</body>

</html>